﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Data;
using System.Windows;
using System.Globalization;

using FlickrNet;

namespace Yorrick.FlickrMetadataSynchr.Flickr
{
    /// <summary>
    /// Converter for <see cref="Photoset"/> to <see cref="string"/>.
    /// </summary>
    [ValueConversion(typeof(Photoset), typeof(string))]
    public class PhotosetNameConverter : IValueConverter
    {
        /// <summary>
        /// Converts from a <see cref="Photoset"/> to a <see cref="string"/>. It formats like "Title (#photos)".
        /// </summary>
        /// <param name="value">The Flickr Photoset to convert.</param>
        /// <param name="targetType">Not used.</param>
        /// <param name="parameter">Not used.</param>
        /// <param name="culture">The <see cref="CultureInfo"/> to use.</param>
        /// <returns></returns>
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            Photoset photoset = value as Photoset;

            if (photoset == null)
            {
                return String.Empty;
            }

            string title = photoset.Title.Replace("&amp;", "&");

            string titleAndNumberOfPhotos = String.Format(culture, "{0} ({1})", title, photoset.NumberOfPhotos);

            return titleAndNumberOfPhotos;
        }

        /// <summary>
        /// Converting back is not supported.
        /// </summary>
        /// <param name="value">The value to convert.</param>
        /// <param name="targetType">Not used.</param>
        /// <param name="parameter">Not used.</param>
        /// <param name="culture">Not used.</param>
        /// <returns></returns>
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotSupportedException();
        }
    }
}